#ifndef __BASE_H__
#define __BASE_H__

/* C++ standard library */
#include <iostream>
#include <sstream>
#include <future>

/* C standard library*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* type define */
#include <type.h>

namespace mdk
{
typedef std::function<void(void)>   VoidEntryFunc;
typedef std::function<void(void *)> FunEntry;
typedef int(*FUNC)(void*);
#if   defined (__WIN32__) || defined (WIN32) || defined (_MSC_VER)
#define GEAR_API __declspec(dllexport)
#else
#define GEAR_API __attribute__((visibility("default")))
#endif

/**
 * Variable-argument unused annotation
 */
#define UNUSED(e, ...)      (void) ((void) (e), ##__VA_ARGS__)

#ifdef __GNUC__
#define LIKELY(x)           (__builtin_expect(!!(x), 1))
#define UNLIKELY(x)         (__builtin_expect(!!(x), 0))
#else
#define LIKELY(x)           (x)
#define UNLIKELY(x)         (x)
#endif

#define SWAP(a, b)          \
    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)

#define MIN(a, b)          ((a) > (b) ? (b) : (a))
#define MAX(a, b)          ((a) > (b) ? (a) : (b))
#define ABS(x)             ((x) >= 0 ? (x) : -(x))

#define CALLOC(size, type)  (type *) calloc(size, sizeof(type))
#define ARRAY_SIZE(a)       (sizeof(a) / sizeof(a[0]))

#define VERBOSE()                                                   \
    do {                                                            \
        printf("%s:%s:%d xxxxxx\n", __FILE__, __func__, __LINE__);  \
    } while (0)

#define ALIGN2(x, a)	(((x) + (a) - 1) & ~((a) - 1))

#define is_alpha(c)  (((c) >=  'a' && (c) <= 'z') || ((c) >=  'A' && (c) <= 'Z'))

 /**
  * Compile-time strlen(3)
  * XXX: Should only used for `char[]'  NOT `char *'
  * Assume string ends with null byte('\0')
  */
#define STRLEN(s)          (sizeof(s) - 1)
}
#endif